﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZOVNP.Model;
using ZOVNP.Model.Abstracts;
using ZOVNP.WinView;
using ZOVNP.WinView.Workplaces.Administrator;
using ZOVNP.WinView.Workplaces.Seller;

namespace ZOVNP.WinView
{
    public partial class MainForm : Form
    {
        private ISupportEngine _engineSupporter;
        private IEngine _engine;
        private IWorkplace _workplace;

        public MainForm(ISupportEngine engineSupported)
        {
            _engineSupporter = engineSupported;
            var engine = _engineSupporter.Current;

            if (engine != null)
            {
                _engine = engine;
                InitializeComponent();
                CustomInitialization();
            }
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            if(_engine == null)
                Close();
        }

        private void CustomInitialization()
        {
            //_workplace = new AdministratorWorkplace(_engine);
            _workplace = new SellerWorkplace(_engine);
            _workplace.PopulateMainContainer(this.tscMain.ContentPanel);
        }

        private void TsbSaveClick(object sender, EventArgs e)
        {
            _workplace.Save();
        }

        private void TsbAddClick(object sender, EventArgs e)
        {
            _workplace.Add();
            //Workspace workspace = new Workspace((IDomainEngine)_engine);
            //OrderFullEditForm frm = new OrderFullEditForm(workspace);
            //frm.Show();
        }

        private void TsbEditClick(object sender, EventArgs e)
        {
            _workplace.Edit();
        }

        private void TsbDeleteClick(object sender, EventArgs e)
        {
            _workplace.Delete();
        }

        private void TsbRefreshClick(object sender, EventArgs e)
        {
            _workplace.Refresh();
        }

        private void TsbPrintClick(object sender, EventArgs e)
        {
            _workplace.Print();
        }

        private void TsbSettingsClick(object sender, EventArgs e)
        {
            
        }
    }
}
